package com.niit.spark.sql.test

import org.apache.spark.sql.{DataFrame, SparkSession}

/**
 * Date:2025/5/12
 * Author：Ys
 * Description:
 */
object GenerateParquet {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder().appName("GenerateParquet").master("local[*]").getOrCreate()
    spark.sparkContext.setLogLevel("ERROR")
    import spark.implicits._

    val data = Seq(
      (1, "2025-01-01", 100.5),
      (2, "2025-01-02", 200.8),
      (3, "2025-01-03", 150.2)
    )
    //创建parquet数据文件
/*
    val df = spark.createDataFrame(data).toDF("id", "date", "value")
    //利用DataFrame去创建一个数据文件
    df.write.parquet("input/sql/data.parquet")
*/

    //读取parquet文件
    val df: DataFrame = spark.read.parquet("input/sql/data.parquet")
    df.show()


    spark.stop()
  }

}
